/**
 * 植物的门请求
 * */
const {
    express,
    db_mysql,
    errorData,
    strLen
} = require('./common-req.js')
const router = express.Router();
/**
 * 获取全部的门
 * */
router.get('/', (req, res) => {
    let countSql = 'select count(*) as count from doors';
    let doorSql = 'select * from doors;'
    db_mysql.select(countSql, null, result => {
        if (result && result.length > 0) {
            let resData = {
                data: [],
                status: 0,
                msg: '获取植物的门的数据成功',
                total: result[0].count
            }
            db_mysql.select(doorSql, null, results => {
                if (results && results.length > 0) {
                    for(var k in results) {
                        var temp = {
                            doorId: results[k].doorId,
                            dCNName: results[k].dCNName,
                            dENName: results[k].dENName
                        }
                        resData.data.push(temp);
                    }
                    res.send(resData);
                } else {
                    errorData.msg = '读取数据失败';
                    res.send(errorData);
                }
            })
        } else {
            errorData.msg = '暂无数据';
            res.send(errorData);
        }
    })
})


module.exports = router;
